/*******************************************************************************
* APPENDIX FIGURES AND TABLES FOR "REGULATORY INCENTIVES FOR INNOVATION: 
THE FDA'S BREAKTHROUGH THERAPY DESIGNATION"
*******************************************************************************/

clear all
version 16.0
pause on
program drop _all
capture log close
set more off

*******************************************************************************
* DEFINE DIRECTORIES
*******************************************************************************

* SET GLOBAL MACRO PATH 
global main ""
cd $main


*******************************************************************************
* SET LOCAL MACROS 
*******************************************************************************

* Set BTD date 
local btd_date "09Jul2012" 

set scheme s2color

********************************************************************************
* TABLE B1: NME SAMPLE BY CALENDAR YEAR 
********************************************************************************

local file table_b1

use analytic_full_public, clear

* Total counts 
gen tot = 1 

* Standard approval counts
gen std = priority == 0 

collapse (sum) tot std priority fast accel orphan btd bbw, by(year_app)

sort year_app 

export excel using "`file'", firstrow(variables) replace

********************************************************************************
* TABLE B2: AVERAGE TIMES TO SUBMISSIONS 
********************************************************************************

local file table_b2

use analytic_full_public, clear

matrix B = J(2,5,.)

local var "p2_sub_day p3_sub_day"

local count = 1

foreach x in `var' {

count 

su `x', detail 

matrix B[`count',1] = round(`r(N)', 1)
matrix B[`count',2] = round(`r(mean)', 1) 

matrix B[`count',3] = round(`r(sd)', 1) 
matrix B[`count',4] = round(`r(min)', 1) 
matrix B[`count',5] = round(`r(max)', 1) 

local count = `count' + 1

}

mat coln B =  "N" "Mean" "SD" "Min" "Max"
esttab matrix(B) using `file'.tex, replace ///
compress coeflabels(r1 "\addlinespace \hspace{3mm} PII to Submission (Days)" r2 "PIII to Submission (Days)") noobs

********************************************************************************
* TABLE B3: ADVERSE EVENTS COUNTS WITHIN 2 AND 6 MONTHS OF APPROVAL
********************************************************************************

local file table_b3 

use analytic_full_public, clear

sort applno 
order applno brandname drugname ae_2m_postap_tot ae_3m_postap_tot ae_4m_postap_tot ae_5m_postap_tot ae_6m_postap_tot
keep applno brandname drugname ae_2m_postap_tot ae_3m_postap_tot ae_4m_postap_tot ae_5m_postap_tot ae_6m_postap_tot

export excel using "`file'", firstrow(variables) replace

********************************************************************************
* TABLE B3: ADVERSE EVENTS COUNTS WITHIN 2 AND 6 MONTHS OF APPROVAL
********************************************************************************

local file table_b3 

use analytic_full_public, clear

sort applno 
order applno brandname drugname ae_2m_postap_tot ae_3m_postap_tot ae_4m_postap_tot ae_5m_postap_tot ae_6m_postap_tot
keep applno brandname drugname ae_2m_postap_tot ae_3m_postap_tot ae_4m_postap_tot ae_5m_postap_tot ae_6m_postap_tot

export excel using "`file'", firstrow(variables) replace


********************************************************************************
* TABLE C1: IMPACT ON PHASE 4 TRIALS 
********************************************************************************

local file table_c1 

use analytic_matched_public, clear

keep if did_samp == 1 

xi: eststo: reg any_p4 btd_new post_btd_new i.year_app, vce(robust)
estadd ysumm
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "N"
estadd local disease "N"
estadd local obs = `e(N)'
estadd local r2_2 = `: display %5.3f e(r2)' 

xi: eststo: reg any_p4 btd_new post_btd_new nda priority fast accel bbw private i.year_app, vce(robust) 
estadd ysumm
estadd local ymean2 = `: display %5.2f e(ymean)' 
estadd local fda "Y"
estadd local disease "N"
estadd local obs = `e(N)'
estadd local r2_2 = `: display %5.3f e(r2)' 

xi: eststo: reg any_p4 btd_new post_btd_new nda priority fast accel bbw private i.atc_level1_id i.year_app, vce(robust)
estadd ysumm
estadd local ymean2 = `: display %5.2f e(ymean)' 
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local r2_2 = `: display %5.3f e(r2)' 

esttab _all using `file'.tex, ///
b(3)  ///
replace se  ///
constant nomtitles  ///
keep(btd_new post_btd_new nda priority private)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs r2_2, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "\$R^2$")) ///
nonotes
eststo clear 

********************************************************************************
* TABLE C2: SUMMARY STATISTICS: POST-BTD SAMPLE
********************************************************************************

local file table_c2 

use analytic_full_public, clear 

merge 1:1 applno using analytic_matched, nogen keepusing(sampaW sampaY sampaX sampA sampB)

* Keep post-2012 drugs only 
keep if sampA == 1 | sampB == 1

count //227 

* keep DID sample only 
gen treat = 1 if sampB == 1 
replace treat = 0 if mi(treat)
gen ctrl = 1 if sampA == 1
replace ctrl = 0 if mi(ctrl)

gen cancer = atc_level1 == "L"
gen metab = atc_level1 == "A"
gen antiinf = atc_level1 == "J"
gen nerv = atc_level1 == "N"

gen firm_drug_rank_h = firm_drug_rank == 2
gen firm_drug_rank_l = firm_drug_rank == 1

* convert to month-level 
foreach outcome in nda_app_day p2_sub_day p3_sub_day { 
replace `outcome' = `outcome'/(30.5)
}

matrix B = J(13,5,.)

local var_compare "nda priority fast accel bbw cancer metab antiinf nerv private nda_app_day p2_sub_day p3_sub_day"

local count = 1

foreach x in  `var_compare' {

ttest `x', by(ctrl)

matrix B[`count',1] = round(`r(mu_1)', 0.01)
matrix B[`count',2] = round(`r(sd_1)', 0.01)

matrix B[`count',3] = round(`r(mu_2)', 0.01)
matrix B[`count',4] = round(`r(sd_2)', 0.01)

matrix B[`count',5] = round(`r(p)', 0.01)

local count = `count' + 1

}

mat coln B =  "Mean" "SD" "Mean" "SD" "T-Test"
esttab matrix(B) using `draft_fd'`file'.tex, replace ///
compress coeflabels(r1 "\addlinespace \hspace{3mm} Small Molecule (0/1)" r2 "\addlinespace \hspace{3mm} Priority Review (0/1)" r3 "\addlinespace \hspace{3mm} Fast Track (0/1)" r4 "\addlinespace \hspace{3mm} Accelerated Approval (0/1)" r5 "\addlinespace \hspace{3mm} Black Box Warning (0/1)" r6 "\addlinespace \hspace{3mm} ATC: Cancer (0/1)" r7 "\addlinespace \hspace{3mm} ATC: Metabolism  (0/1)" r8 "\addlinespace \hspace{3mm} ATC: Antiinfectives (0/1)" r9 "\addlinespace \hspace{3mm} ATC: Nervous System  (0/1)" r10 "\addlinespace \hspace{3mm}Sponsor: Private Firm (0/1)" r11 "\addlinespace \hspace{3mm} Regulatory Review (Months)" r12 "\addlinespace \hspace{3mm} Phase 2 to Regulatory Review (Months)" r13 "\addlinespace \hspace{3mm} Phase 3 to Regulatory Review (Months)") noobs

********************************************************************************
* APPENDIX TABLE C4: ASSIGNING UNMATCHED DRUGS AS IMPUTED NON-BTD DRUGS 
********************************************************************************

local file table_c4

use analytic_matched_public, clear

replace sampaX = 1 if mi(did_samp)

foreach outcome in nda_app_day p3_sub_day p2_sub_day  {
	
xi: eststo: nbreg `outcome' btd_new post_btd_new i.year_app nda priority fast accel bbw private i.atc_level1_id, vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local loglik = `: display %5.0f  e(ll)'
}

esttab _all using  `file'.tex, ///
b(3)  ///
replace se  ///
constant nomtitles  ///
keep(btd_new post_btd_new nda priority private)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs loglik, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "log likelihood")) ///
nonotes
eststo clear 

********************************************************************************
* APPENDIX TABLE C5:  CONTROLLING FOR DRUG COHORT 
********************************************************************************

local file table_c5 

use analytic_matched_public, clear

keep if did_samp == 1 

gen year_sub = year(date_sub)

foreach outcome in nda_app_day p3_sub_day p2_sub_day {
	
xi: eststo: nbreg `outcome' btd_new post_btd_new i.year_sub nda priority fast accel bbw private i.atc_level1_id, vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local loglik = `: display %5.0f  e(ll)'
}

esttab _all using `file'.tex, ///
b(3)  ///
replace se  ///
constant nomtitles  ///
keep(btd_new post_btd_new nda priority private)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs loglik, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "log likelihood")) ///
nonotes
eststo clear 


********************************************************************************
* APPENDIX TABLE C6: CONTROLLING FOR NOVELTY OF DRUG MECHANISM OF ACTION 
********************************************************************************

local file table_c6 

use analytic_matched_public, clear

keep if did_samp == 1 

* Account for drugs with missing drug actions  
gen any_new_drug_action_mi = mi(any_new_drug_action)
replace any_new_drug_action = 2 if any_new_drug_action_mi == 1

foreach outcome in nda_app_day p3_sub_day p2_sub_day {
	
xi: eststo: nbreg `outcome' btd_new post_btd_new i.year_app nda priority fast accel bbw private i.atc_level1_id any_new_drug_action any_new_drug_action_mi , vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local loglik = `: display %5.0f  e(ll)'
}

esttab _all using `file'.tex, ///
b(3)  ///
replace se  ///
constant nomtitles  ///
keep(btd_new post_btd_new nda priority private)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs loglik, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "log likelihood")) ///
nonotes
eststo clear 

********************************************************************************
* TABLE C7: IMPACT ON ADVERSE EVENT LEVELS 
*********************************************************************************

local file table_c7 

use analytic_matched_public, clear

keep if did_samp == 1

foreach outcome in ae_2m_postap_tot ae_3m_postap_tot ae_4m_postap_tot ae_5m_postap_tot  ae_6m_postap_tot {

xi: eststo: nbreg `outcome' btd_new post_btd_new i.year_app nda priority fast accel bbw private i.atc_level1_id, vce(robust) 
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
local loglik `: display %5.0f e(ll)' 
estadd local loglik = `loglik'
estadd local obs = `e(N)'
	
}
esttab _all using `file'.tex, ///
b(3)  ///
replace se  ///
constant nomtitles  ///
keep(btd_new post_btd_new nda priority private)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs  loglik, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "log likelihood")) ///
nonotes
eststo clear 

********************************************************************************
* APPENDIX TABLE C8: EXCLUDE CLINICAL TRIALS THAT OCCUR POST-DESIGNATION 
********************************************************************************

local file table_c8

use analytic_matched_public, clear

keep if did_samp == 1 

foreach outcome in p3_sub_day {
	
xi: eststo: nbreg `outcome' btd_new post_btd_new i.year_app nda priority fast accel bbw private i.atc_level1_id , vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local loglik = `: display %5.0f  e(ll)'

drop if p3_start < date_btd & !mi(date_btd) & !mi(p3_start)

xi: eststo: nbreg `outcome' btd_new post_btd_new i.year_app nda priority fast accel bbw private i.atc_level1_id , vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local loglik = `: display %5.0f  e(ll)'
}

use analytic_matched, clear

keep if did_samp == 1 

foreach outcome in p2_sub_day {
	
xi: eststo: nbreg `outcome' btd_new post_btd_new i.year_app nda priority fast accel bbw private i.atc_level1_id , vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local loglik = `: display %5.0f  e(ll)'

drop if p2_start < date_btd & !mi(date_btd) & !mi(p2_start)

xi: eststo: nbreg `outcome' btd_new post_btd_new i.year_app nda priority fast accel bbw private i.atc_level1_id , vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local loglik = `: display %5.0f  e(ll)'
}

esttab _all using `file'.tex, ///
b(3)  ///
replace se  ///
constant nomtitles  ///
keep(btd_new post_btd_new nda priority private)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs loglik, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "log likelihood")) ///
nonotes
eststo clear 


********************************************************************************
* APPENDIX TABLE C9: NO CONTROLS FOR DEVELOPER TYPE
********************************************************************************

local file table_c9 

use analytic_matched_public, clear

keep if did_samp == 1

gen cancer = atc_level1 == "L"

foreach outcome in nda_app_day p3_sub_day p2_sub_day {

xi: eststo: nbreg `outcome' btd_new post_btd_new i.year_app nda priority fast accel bbw i.atc_level1_id, vce(robust) 
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
local loglik `: display %5.0f e(ll)' 
estadd local loglik = `loglik'
estadd local obs = `e(N)'

}

esttab _all using `file'.tex, ///
b(3)  ///
replace se  ///
constant nomtitles  ///
keep(btd_new post_btd_new nda priority)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs  loglik, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "log likelihood")) ///
nonotes 
eststo clear 

********************************************************************************
* APPENDIX TABLE C10: OLS SPECIFICATION
********************************************************************************

local file table_c10

use analytic_matched_public, clear

keep if did_samp == 1 

foreach outcome in nda_app_day p3_sub_day p2_sub_day  {
	
xi: eststo: reg `outcome' btd_new post_btd_new i.year_app nda priority fast accel bbw private i.atc_level1_id, vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local r2_2 = `: display %5.3f e(r2)' 
}

esttab _all using `file'.tex, ///
b(3)  ///
replace se  ///
constant nomtitles  ///
keep(btd_new post_btd_new nda priority private)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs r2_2, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "\$R^2$")) ///
nonotes
eststo clear 

********************************************************************************
* APPENDIX TABLE C11: RESTRICTED TO 2010-2018 APPROVALS
********************************************************************************

local file table_c11

use analytic_matched_public, clear

keep if year_app >= 2010 

keep if did_samp == 1 

foreach outcome in nda_app_day p3_sub_day p2_sub_day  {
	
xi: eststo: nbreg `outcome' btd_new post_btd_new i.year_app nda priority fast accel bbw private i.atc_level1_id, vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local loglik = `: display %5.0f  e(ll)'
}

esttab _all using `file'.tex, ///
b(3)  ///
replace se  ///
constant nomtitles  ///
keep(btd_new post_btd_new nda priority private)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs loglik, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "log likelihood")) ///
nonotes
eststo clear 


********************************************************************************
* APPENDIX TABLE C12: FAST TRACK AS PLACEBO
********************************************************************************

local file table_c12

use analytic_matched_fast_public, clear
	
keep if did_samp == 1

foreach outcome in nda_app_day p3_sub_day p2_sub_day {


xi: eststo: nbreg `outcome'  fast_new post_fast_new i.year_app nda priority accel bbw private i.atc_level1_id, vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
local loglik `: display %5.0f e(ll)' 
estadd local loglik = `loglik'
estadd local obs = `e(N)'

}

esttab _all using `file'.tex, ///
b(3) replace se  ///
constant nomtitles  ///
keep(fast_new post_fast_new nda priority private)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs  loglik, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "log likelihood")) ///
nonotes
eststo clear 

********************************************************************************
* APPENDIX FIGURE D1: TRENDS IN TIME TO MARKET 
********************************************************************************

local file figure_d1  

local title_nda_app_day "Panel A. Regulatory Review"
local title_p3_sub_day "Panel B. Phase III to Regulatory Review"
local title_p2_sub_day "Panel C. Phase II to Regulatory Review"

use analytic_matched_public, clear

collapse (mean) nda_app_day p3_sub_day p2_sub_day, by(year_app)

twoway (connect nda_app_day year_app, mcolor(black) lcolor(black) lwidth(thin) lpattern(solid)) ///
(connect p3_sub_day year_app, mcolor(black) lcolor(black) lwidth(thin) lpattern(solid) msymbol(Oh)) ///
(connect p2_sub_day year_app, mcolor(black) lcolor(black) lwidth(thin) lpattern(dash) msymbol(t) ///
title("", size(medium)) ///
ytitle("Days", size(medium)) ///
xtitle("Approval Year", size(medium)) ///
ylabel(, angle(horizontal) labsize(small) tlength(.75)) ///
xlabel(2006(2)2018,labsize(small) tlength(.75)) ///
xline(2012, lcolor(red) lpattern(solid)) ///
legend(label(1 "Regulatory Review") label(2 "Phase III to Regulatory Review") label(3 "Phase II to Regulatory Review") rows(3)  position(6) region(lcolor(black))) ///
graphregion(color(white))) 
graph export `file'.pdf, replace

********************************************************************************
* APPENDIX FIGURE D2: TRENDS IN TIME TO MARKET FOR BTD vs. NON-BTD 
********************************************************************************

local title_p3_sub_day "Panel A. Phase III to Regulatory Review (True)"
local title_p2_sub_day "Panel C. Phase II to Regulatory Review (True)"

local i 1

foreach outcome in p3_sub_day p2_sub_day {
	
use analytic_matched_public, clear

collapse (mean) `outcome', by(btd year_app)

twoway (connect `outcome' year_app if btd == 1 & year_app <= 2018, mcolor(black) lcolor(black) lwidth(thin) lpattern(solid)) ///
(connect `outcome' year_app if btd == 0 & year_app <= 2018, mcolor(black) lcolor(black) lwidth(medium) msymbol(t) lpattern(dash) ///
title("`title_`outcome''", size(medium)) ///
ytitle("Days", size(medium)) ///
xtitle("Approval Year", size(medium)) ///
ylabel(, angle(horizontal) labsize(small) tlength(.75)) ///
xlabel(2006(2)2018,labsize(small) tlength(.75)) ///
xline(2012, lcolor(red) lpattern(solid)) ///
legend(label(1 "True BTD") label(2 "True Non-BTD") rows(2) size(medium) position(6) region(lcolor(black))) ///
graphregion(color(white))) 
graph save g`i'.gph, replace

local i = `i' + 1 

}

local title_p3_sub_day "Panel B. Phase III to Regulatory Review (Imputed + True)"
local title_p2_sub_day "Panel D. Phase II to Regulatory Review (Imputed + True)"

local i = 3 

foreach outcome in p3_sub_day p2_sub_day {
	
use analytic_matched_public, clear

collapse (mean) `outcome', by(btd_new year_app)

twoway (connect `outcome' year_app if btd_new == 1 & year_app <= 2018, mcolor(black) lcolor(black) lwidth(thin) lpattern(solid)) ///
(connect `outcome' year_app if btd_new == 0 & year_app <= 2018, mcolor(black) lcolor(black) lwidth(medium) msymbol(t) lpattern(dash) ///
title("`title_`outcome''", size(medium)) ///
ytitle("Days", size(medium)) ///
xtitle("Approval Year", size(medium)) ///
ylabel(, angle(horizontal) labsize(small) tlength(.75)) ///
xlabel(2006(2)2018,labsize(small) tlength(.75)) ///
xline(2012, lcolor(red) lpattern(solid)) ///
legend(label(1 "Imputed + True BTD") label(2 "Imputed + True Non-BTD") rows(2) size(medium) position(6) region(lcolor(black))) ///
graphregion(color(white))) 
graph save g`i'.gph, replace

local i = `i' + 1 

}

local file figure_d2
graph combine g1.gph g3.gph g2.gph g4.gph , ///
col(2) scale(.8) xsize(9) ysize(7) ycommon graphregion(color(white))
graph export `file'.pdf, replace


* CLEAN UP 
capture noisily rm g1.gph 
capture noisily rm g3.gph 
capture noisily rm g2.gph 
capture noisily rm g4.gph 


********************************************************************************
* APPENDIX TABLE D1 AND D2: IMPUTED AND TRUE NON-BTD SAMPLE
********************************************************************************

foreach drugtype in  nonbtd btd    {

use analytic_matched_public, clear

gen cancer = atc_level1 == "L"
gen metab = atc_level1 == "A"
gen antiinf = atc_level1 == "J"
gen nerv = atc_level1 == "N"

if "`drugtype'" == "nonbtd" {

keep if sampA == 1 | sampaX == 1 

gen impute = 0 if sampA == 1
replace impute = 1 if sampaX == 1 
gen nimpute = impute == 0 

local file table_d1

}

if "`drugtype'" == "btd" {

keep if sampB == 1 | sampaY == 1 

gen impute = 0 if sampB == 1
replace impute = 1 if sampaY == 1 
gen nimpute = impute == 0 

local file table_d2 

}

gen firm_drug_rank_h = firm_drug_rank == 2
gen firm_drug_rank_l = firm_drug_rank == 1

* convert to month-level 
foreach outcome in nda_app_day p2_sub_day p3_sub_day { 
replace `outcome' = `outcome'/(30.5)
}

matrix B = J(14,5,.)

local var_compare "nda priority fast accel bbw cancer metab antiinf nerv private firm_drug nda_app_day p2_sub_day p3_sub_day "

local count = 1

foreach x in  `var_compare' {

ttest `x', by(nimpute)

matrix B[`count',1] = round(`r(mu_1)', 0.01)
matrix B[`count',2] = round(`r(sd_1)', 0.01)

matrix B[`count',3] = round(`r(mu_2)', 0.01)
matrix B[`count',4] = round(`r(sd_2)', 0.01)

matrix B[`count',5] = round(`r(p)', 0.01)

local count = `count' + 1

}

mat coln B =  "Mean" "SD" "Mean" "SD" "T-Test"
esttab matrix(B) using `draft_fd'`file'.tex, replace ///
compress coeflabels(r1 "\addlinespace \hspace{3mm} Small Molecule (0/1)" r2 "\addlinespace \hspace{3mm} Priority Review (0/1)" r3 "\addlinespace \hspace{3mm} Fast Track (0/1)" r4 "\addlinespace \hspace{3mm} Accelerated Approval (0/1)" r5 "\addlinespace \hspace{3mm} Black Box Warning (0/1)" r6 "\addlinespace \hspace{3mm} ATC: Cancer (0/1)" r7 "\addlinespace \hspace{3mm} ATC: Metabolism  (0/1)" r8 "\addlinespace \hspace{3mm} ATC: Antiinfectives (0/1)" r9 "\addlinespace \hspace{3mm} ATC: Nervous System  (0/1)" r10 "\addlinespace \hspace{3mm}Sponsor: Private Firm (0/1)" r11 "\addlinespace \hspace{3mm} Firm Experience (\# Approved Drugs) " r12 "\addlinespace \hspace{3mm} Regulatory Review (Months)" r13 "\addlinespace \hspace{3mm} Phase 2 to Regulatory Review (Months)" r14 "\addlinespace \hspace{3mm} Phase 3 to Regulatory Review (Months)") noobs

}

********************************************************************************
* APPENDIX TABLE D4: CONTROLLING FOR TIME TRENDS 
********************************************************************************

use analytic_matched_public, clear

local file table_d4

keep if did_samp == 1 

* Create time trend 
gen trend = year_app - 2000 

foreach outcome in nda_app_day p3_sub_day p2_sub_day {
	
xi: eststo: nbreg `outcome' btd_new post_btd_new trend i.year_app nda priority fast accel bbw private i.atc_level1_id, vce(robust)
estadd ysumm 
estadd local ymean2 = `: display %5.2f e(ymean)'  
estadd local fda "Y"
estadd local disease "Y"
estadd local obs = `e(N)'
estadd local loglik = `: display %5.0f  e(ll)'
}

esttab _all using `file'.tex, ///
b(3)  ///
replace se  ///
constant nomtitles  ///
keep(btd_new post_btd_new nda priority private)  ///
m label nonotes compress nodepvars wrap star(* 0.10 ** 0.05 *** 0.001)  ///
stats(ymean2 fda disease obs loglik, labels("Mean"  "Controls: Drug Characteristics" "Controls: Disease" "Observations" "log likelihood")) ///
nonotes
eststo clear 
